<!--
	作者：weixin
	时间：2017-03-30
	描述：企业管理页面
-->
<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>企业管理-后台管理系统</title>
		<link rel="stylesheet" href="${rc.contextPath}/bootstrap/css/bootstrap.css" />
		<link rel="stylesheet" href="${rc.contextPath}/zui/css/zui.css" />
		<script src="${rc.contextPath}/js/jquery.1.10.1.min.js"></script>
		<script type="text/javascript" src="${rc.contextPath}/zui/js/zui.js"></script>
	</head>

	<body>
		<ul class="nav nav-tabs" id="adminTab">
			<li>
				<a href="${rc.contextPath}/admin/index" data-togggle="tab">首页</a>
			</li>
			<li class="active">
				<a href="${rc.contextPath}/admin/erterprise_manage" data-togggle="tab">企业管理及审核</a>
			</li>
			<li>
				<a href="${rc.contextPath}/admin/forum_manage" data-togggle="tab">论坛管理</a>
			</li>
			<li>
				<a href="message.html" data-togggle="tab">消息</a>
			</li>
			<li class="pull-right">
				<a href="#" class="dropdown-toggle" data-toggle="dropdown">
					<img src="${rc.contextPath}/img/leader_default.png" width="20px" />管理员<span class="caret"></span>
				</a>
				<ul class="dropdown-menu">
					<li>
						<a href="#">账号设置</a>
					</li>
					<li>
						<a href="#">退出</a>
					</li>
				</ul>
			</li>
		</ul>

		<!--  左侧菜单  -->
		<div style="margin-top: 20px;" class="col-xs-2">
			<nav class="menu" data-toggle="menu" style="width: 200px;">
				<ul class="nav nav-primary">

					<li class="active show nav-parent">
						<a href="javascript:;"><i class="icon icon-group"></i> 公司</a>
						<ul class="nav">
							<li class="active">
								<a href="enterprise_manage.html"><i class="icon icon-cog"></i> 公司信息管理</a>
							</li>
							<li>
								<a href="${rc.contextPath}/admin/enterprise_check/1">
									<i class="icon icon-trophy"></i> 公司认证审核<span class="label label-badge pull-right" id="uncheckCompanyCount">5</span>
								</a>
							</li>
							<li>
								<a href="${rc.contextPath}/admin/enterprise_user_check/1" >
									<i class="icon icon-trophy"></i> 企业用户审核<span class="label label-badge pull-right" id="uncheckUserCount">0</span>
								</a>
							</li>
							<li>
								<a href="${rc.contextPath}/admin/addcompany"><i class="icon icon-plus"></i> 添加公司</a>
							</li>
						</ul>
					</li>

					<li class="active show nav-parent">
						<a href="javascript:;"><i class="icon icon-book"></i> 招聘</a>
						<ul class="nav">
							<li>
								<a href="${rc.contextPath}/admin/job_manage"><i class="icon icon-list-ul"></i> 招聘管理</a>
							</li>
							<li>
								<a href="${rc.contextPath}/admin/addjob"><i class="icon icon-pencil"></i> 发布招聘</a>
							</li>
						</ul>
					</li>
				</ul>
			</nav>
		</div>

		<div class="col-xs-8" style="margin-top: 20px;">
			<div class="panel">
				<form action="${rc.contextPath}/admin/searchcompany" method="get">
					<div class="panel-body">
						<div class="col-xs-2">
							<select name="searchtype" class="form-control">
								<option value="0" selected="selected">公司名称</option>
								<!-- <option value="1">公司所在地</option> -->
							</select>
						</div>
						<div class="col-xs-6">
							<input type="text" class="form-control" name="keyword" />
						</div>
						<div class="col-xs-4">
							<input type="submit" class="btn btn-primary" value="搜索公司" />
						</div>
					</div>
				</form>
				<input type="hidden" value="$!keyword" id="searchctx"/>
			</div>

			<table class="table table-striped">
				<thead>
					<tr>
						<th>logo</th>
						<th width="40%">公司名称</th>
						<th>所在城市</th>
						<th>行业领域</th>
						<th>公司规模</th>
						<th>发布人id</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					#foreach($!company in $!companyList)
					<tr>
						<td><img src="http://127.0.0.1:8080/image/companylogo/$!{company.company_logo}" width="30" /></td>
						<td>
							<a href="#">$!company.company_name</a>
						</td>
						<td>$!company.location_name</td>
						<td>$!company.domain_name</td>
						#if($!company.company_scale == 0)
						<td>少于15人</td>
						#end
						#if($!company.company_scale == 1)
						<td>15-50人</td>
						#end
						#if($!company.company_scale == 2)
						<td>50-150人</td>
						#end
						#if($!company.company_scale == 3)
						<td>150-500人</td>
						#end
						#if($!company.company_scale == 4)
						<td>500-2000人</td>
						#end
						#if($!company.company_scale == 5)
						<td>2000人以上</td>
						#end
						<td>$!company.company_creater</td>
						<td>
							<a href="#" data-toggle="modal" data-target="#editCompany" data-id="$!company.id">修改</a>&nbsp;|&nbsp;
							<button type="button" class="btn btn-mini unload" data-id="$!company.id">删除</button> &nbsp;|&nbsp;
							<button type="button" class="btn btn-mini addhot" data-id="$!company.id">每日推荐</button>
						</td>
					</tr>
					#end
				</tbody>
			</table>

			<div class="pagination" style="margin: 0px 0 20px;">$!page.pageString</div>

		</div>


		<!--------------------------------------- 修改公司弹出对话框  ------------------------------------->
		<div class="modal fade" id="editCompany">
			<div class="modal-dialog">
				<form class="form-horizontal" action="#" id="editCompanyForm">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
						<h4 class="modal-title">修改公司信息</h4>
					</div>
					<div class="modal-body">
						
							<div class="form-group">
								<label for="exampleInputAccount4" class="col-sm-2">公司logo</label>
								<div class="col-md-6 col-sm-10">
									<img class="img-thumbnail" id="show_company_logo" width="50px"/>
									<input type="hidden" name="company.company_logo" id="company_logo"/>
									<input type="file" class="form-control" id="exampleInputAccount4">
								</div>
							</div>
							<div class="form-group">
								<label for="exampleInputAccount4" class="col-sm-2">公司全称</label>
								<div class="col-md-6 col-sm-10">
									<input type="text" class="form-control" id="company_name" name="company.company_name" placeholder="请输入公司全称">
									<input type="hidden" name="company.id" />
								</div>
							</div>
							<div class="form-group">
								<label for="exampleInputPassword4" class="col-sm-2">公司网址</label>
								<div class="col-md-6 col-sm-10">
									<input type="text" class="form-control" id="company_website" name="company.company_website" placeholder="密码">
								</div>
							</div>
							<div class="form-group">
								<label for="exampleInputPassword4" class="col-sm-2">公司所在城市</label>
								<div class="col-md-6 col-sm-10">
									<input type="text" class="form-control" id="company_location" name="company.company_location" placeholder="密码">
								</div>
							</div>
							<div class="form-group">
								<label for="exampleInputAddress1" class="col-sm-2">行业领域</label>
								<div class="col-md-6 col-sm-10">
									<select class="form-control" id="company_domain" name="company.company_domain">
									#foreach($!domain in $!domainList)
										<option value="$!domain.id">$!domain.domain_name</option>
									#end
									</select>
								</div>
							</div>
							<div class="form-group">
								<label for="exampleInputAddress1" class="col-sm-2">公司规模</label>
								<div class="col-md-6 col-sm-10">
									<select class="form-control" id="company_scale" name="company.company_scale">
										<option value="0">少于15人</option>
										<option value="1">15-50人</option>
										<option value="2">50-150人</option>
										<option value="3">150-500人</option>
										<option value="4">500-2000人</option>
										<option value="5">2000人以上</option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label for="exampleInputAddress1" class="col-sm-2">发展阶段</label>
								<div class="col-md-6 col-sm-10">
									<select class="form-control" id="company_develop" name="company.company_develop">
										<option value="0">未融资</option>
										<option value="1">天使轮</option>
										<option value="2">A轮</option>
										<option value="3">B轮</option>
										<option value="4">C轮</option>
										<option value="5">D轮以上</option>
										<option value="6">上市公司</option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label for="company_brief" class="col-sm-2">一句话简介</label>
								<div class="col-md-6 col-sm-10">
									<input type="text" class="form-control" id="company_brief" name="company.company_brief" placeholder="简介">
								</div>
							</div>
							<div class="form-group">
								<label for="company_detail" class="col-sm-2">详细介绍</label>
								<div class="col-md-6 col-sm-10">
									<input type="hidden" name="companyDetail.id"/>
									<textarea placeholder="请分段详细描述公司简介、企业文化等" name="companyDetail.detail_content" id="detail_content"></textarea>	
								</div>
							</div>
							<div class="form-group">
								<label for="product_image" class="col-sm-2">产品海报</label>
								<div class="col-md-6 col-sm-10">
									<img class="img-thumbnail" id="show_product_image" src="${rc.contextPath}/img/logo_default.png" width="50px"/>
									<input type="hidden" id="product_image" name="product.product_image"/>
									<input type="file" class="form-control">
								</div>
							</div>
							<div class="form-group">
								<label for="product_name" class="col-sm-2">产品名称</label>
								<div class="col-md-6 col-sm-10">
									<input type="hidden" name="product.id"/>
									<input type="text" class="form-control" id="product_name" name="product.product_name" placeholder="产品名称">
								</div>
							</div>
							<div class="form-group">
								<label for="product_url" class="col-sm-2">产品链接</label>
								<div class="col-md-6 col-sm-10">
									<input type="text" class="form-control" id="product_url" name="product.product_url" placeholder="产品链接">
								</div>
							</div>
							<div class="form-group">
								<label for="product_brief" class="col-sm-2">产品简介</label>
								<div class="col-md-6 col-sm-10">
									<input type="text" class="form-control" id="product_brief" name="product.product_brief" placeholder="产品简介">
								</div>
							</div>
						
					</div>

					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
						<button type="reset" style="display: none;">还原</button>
						<button type="button" class="btn btn-primary" id="update">保存</button>
					</div>
				</div>
				</form>
			</div>
		</div>
		<!--------------------------------------- end  ------------------------------------------------>

	</body>
	<script type="text/javascript">
	$(".unload").click(function(){
			if(confirm("是不是确认删除咯？")){
				jQuery.getJSON('${rc.contextPath}/admin/deleteCompany?id='+$(this).data("id"),function(data){
					if(data.code == 200){
						(new jQuery.zui.ModalTrigger({
							custom : data.info
						})).show({hidden: function(){
							location.reload();
						}});
					}else{
						(new jQuery.zui.ModalTrigger({
							custom : data.info
						})).show();
					}
				})
			}
		});
	$(".addhot").click(function(){
		if(confirm("确认推荐？")){
			jQuery.getJSON('${rc.contextPath}/admin/addhotcompany?id='+$(this).data("id"),function(data){
				if(data.code == 200){
					(new jQuery.zui.ModalTrigger({
						custom : data.info
					})).show({hidden: function(){
						location.reload();
					}});
				}else{
					(new jQuery.zui.ModalTrigger({
						custom : data.info
					})).show();
				}
			})
		}
	});
	
	$(document)
	.on(
			"click",
			".pagination a",
			function(e) {
				var pageNum = $(this).attr("pageData");
				if (pageNum == 0 || isNaN(pageNum)) {
					return;
				}
				var sctx = $("#searchctx").val();
				if(sctx!=null){
					window.location.href = "${rc.contextPath}/admin/searchcompany/"+ pageNum +"?keyword="+sctx;
				}
				window.location.href = "${rc.contextPath}/admin/enterprise_manage/"+ pageNum;
			});
	
	$('#editCompany').on('show.zui.modal', function (e) {
		console.log("aa");
		jQuery.getJSON("${rc.contextPath}/admin/queryCompany?id="+$(e.relatedTarget).data("id"),function(data){
			console.log(data.company.company_logo);
			$("input[name='company.id']").val(data.company.id);
			$("input[name='product.id']").val(data.product.id);
			
			if(data.company.company_logo!=null){
				console.log(data.company.company_logo);
				$("#show_company_logo").attr("src","http://127.0.0.1:8080/image/companylogo/"+data.company.company_logo);
				$("input[name='company.company_logo']").val(data.company.company_logo);
			}
			if(data.product.product_image){
				$("#show_product_image").attr("src","http://127.0.0.1:8080/image/productimage/"+data.product.product_image);
				$("input[name='product.product_image']").val(data.product.product_image);
			}
			$("input[name='company.company_name']").val(data.company.company_name);
			$("input[name='company.company_website']").val(data.company.company_website);
			$("input[name='company.company_location']").val(data.company.company_location);
			$("select[name='company.company_domain']").val(data.company.company_domain);
			$("select[name='company.company_scale']").val(data.company.company_scale);
			$("select[name='company.company_develop']").val(data.company.company_develop);
			$("input[name='company.company_brief']").val(data.company.company_brief);
			$("input[name='product.product_name']").val(data.product.product_name);
			$("input[name='product.product_url']").val(data.product.product_url);
			$("input[name='product.product_brief']").val(data.product.product_brief);
			$("textarea[name='companyDetail.detail_content']").val(data.companyDetail.detail_content);
			$("input[name='companyDetail.id']").val(data.companyDetail.id);
		});
	});
	$("#editCompany").on('hide.zui.modal',function(e){
		$("button[type='reset']").trigger("click");
	})
	
	$("#update").click(function(){
		jQuery.post("${rc.contextPath}/admin/updateCompany", $("#editCompanyForm").serialize(), function(data) {
				(new jQuery.zui.ModalTrigger({
					custom : data.info
				})).show({hidden: function(){
					if(data.code == 200){
						location.reload();
						//window.location.href = "${rc.contextPath}/admin/addcompany";
					}
				}});
		}, 'json');
	});
	
	$(function(){
		jQuery.getJSON('${rc.contextPath}/admin/getUncheckEnterpriseUserCount',function(data){
			if(data!=0){
				$("#uncheckUserCount").html(data);
			}
		});
		jQuery.getJSON('${rc.contextPath}/admin/getUncheckEnterpriseCount',function(data){
			if(data!=0){
				$("#uncheckCompanyCount").html(data);
			}
		})
	});
	</script>
</html>